package com.kukudexin;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author: 酷酷的鑫
 * @Date: 2021/12/8 13:52
 * @description:  方法泛型
 *  格式
 *      方法修饰符  <T> 返回值数据类型 方法名（<T> 形参列表...）{}
  */
public class Test12 {
    public static void main(String[] args) {
        String [] strArr = {"hello","world","wkcto"};
        Collection<String> collection = new ArrayList<>();
        copyArrayToCollection(strArr, collection);
        System.out.println(collection);
        Integer[] intArr = {54,32,76,98};
        Collection<Integer> collection2 = new ArrayList<>();
        copyArrayToCollection(intArr, collection2);
        System.out.println(collection2);

    }

    public static <T> void copyArrayToCollection(T [] arr, Collection<T> collection){
        for (T o : arr) {
            collection.add(o);
        }
    }
}
